/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer.jxmap.render;

import java.awt.image.DirectColorModel;
import java.awt.image.Raster;
import nl.cloudfarming.client.geoviewer.Palette;

/**
 *
 * @author Timon Veenstra
 */
public class PaletteColorModel extends DirectColorModel {

    private static final int RED = 0x00ff0000; //    64-32-16-8-4-2-1
    private static final int GREEN = 0x0000ff00;
    private static final int BLUE = 0x000000ff;
    private static final int ALPHA = 0xff000000;
    private final Palette palette;

    //24 = 00000000 00000000 00000000 00000000
    //16 = 0010000
    //8 =  0001000
    // 00110000 << 0011000
    public PaletteColorModel(Palette palette) {
        super(32,
                RED, // Red
                GREEN, // Green
                BLUE, // Blue
                ALPHA // Alpha
                );
        this.palette = palette;
    }


    @Override
    public boolean isCompatibleRaster(Raster raster) {
        return true;
    }

    @Override
    public int getRGB(Object inData) {
        return palette.getColorForValue(inData).getRGB();
    }

}
